home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
Book Chapters
/
10 - Networking
/
NovelNetwar
/
misc.c
< prev
next >
Wrap
Text File
|
1995-05-12
|
2KB
|
174 lines
// Various miscellaneous functions....
#include "NovelNetwar.h"
#include <Traps.h>
OSErr BreakKey(void)
{
EventRecord theEvent;
char theChar;
int theResult;
theResult = false;
if (EventAvail(keyDownMask+autoKeyMask,&theEvent))
{
theChar = theEvent.message & charCodeMask;
if (theEvent.modifiers&cmdKey && theChar=='.')
{
theResult = true;
FlushEvents(keyDownMask+autoKeyMask,0);
}
}
return(theResult);
}
OSErr ShiftKey(void)
{
KeyMap theKeyMap;
GetKeys(theKeyMap);
if (((unsigned char *) theKeyMap)[7] & 0x01)
return(true);
else
return(false);
}
OSErr OptionKey(void)
{
KeyMap theKeyMap;
GetKeys(theKeyMap);
if (((unsigned char *) theKeyMap)[7] & 0x04)
return(true);
else
return(false);
}
OSErr CommandKey(void)
{
KeyMap theKeyMap;
GetKeys(theKeyMap);
if (((unsigned char *) theKeyMap)[6] & 0x80)
return(true);
else
return(false);
}
OSErr CtrlKey(void)
{
KeyMap theKeyMap;
GetKeys(theKeyMap);
if (((unsigned char *) theKeyMap)[7] & 0x04)
return(true);
else
return(false);
}
OSErr CapsLock(void)
{
KeyMap theKeyMap;
GetKeys(theKeyMap);
if (theKeyMap[1] & 0x02)
return(true);
else
return(false);
}
void getGrayRgnRect(Rect *theRect)
{
RgnHandle theGrayRgnHandle;
SetRect(theRect,qd.screenBits.bounds.left+10,qd.screenBits.bounds.top+25,qd.screenBits.bounds.right-10,qd.screenBits.bounds.bottom-25);
theGrayRgnHandle = GetGrayRgn();
if (theGrayRgnHandle)
*theRect = (**theGrayRgnHandle).rgnBBox;
}
void mystrncpy(register char *s1, register char *s2,register long n)
{
if (n > 0L)
{
n--;
while (*s2 && n--)
*s1++ = *s2++;
*s1 = 0;
}
}
void mystrncat(register char *s1, register char *s2,register long n)
{
if (n > 0L)
{
while (*s1 && n)
{
s1++;
n--;
}
if (n > 0L)
{
n--;
while (*s2 && n--)
*s1++ = *s2++;
*s1 = 0;
}
}
}
OSErr TrapAvailable(int theTrap)
{
if (NGetTrapAddress(theTrap, OSTrap) == NGetTrapAddress(0x009F,OSTrap))
return(TRAPABSENT);
else
return(noErr);
}